<template>
  <div>
    <svg-icon v-if="isFull" class="myicon" icon-class="exit-fullscreen" @click="toggle" />
    <svg-icon v-else class="myicon" icon-class="fullscreen" @click="toggle" />
  </div>
</template>

<script>
import ScreenFull from 'screenfull'
export default {
  name: 'ScreenFull',
  data() {
    return {
      // 控制是否全屏
      isFull: false
    }
  },
  methods: {
    toggle() {
      // 1. 判断当前浏览器是否支持全屏
      if (ScreenFull.isEnabled) {
        // 全屏和取消全屏
        ScreenFull.toggle()
        // console.log(ScreenFull.toggle + '')
        // 切换图标
        this.isFull = !this.isFull
      } else {
        this.$message.warning('您的浏览器不支持全屏功能')
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.myicon {
  width:20px;
  height:20px;
  fill: white;
  cursor: pointer;
}
</style>
